<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>节点增加</title>
		<style>
			#p2 img{
				height: 120px;
				width: 200px;
			}
		</style>
		<script>
			function AddPic(){
				//加一个图片
				let i=document.createElement("img");
				i.setAttribute("src","../img/fink.png");
				document.getElementById("p2").appendChild(i);
			}
			function AddPic2(){
				//加一个图片
				let i=document.createElement("img");
				i.setAttribute("src","../img/lovk.jpg");
				let p2=document.getElementById("p2");
				p2.insertBefore(i,p2.firstElementChild);
			}
			function kelong(){
				let p2=document.getElementById("p2").cloneNode(true);
				document.body.appendChild(p2);
			}
			//删除p2的最后一个
			function delNode(){
				let p2=document.getElementById("p2");
				//p2.removeChild(p2.lastElementChild.previousElementSibling);
				p2.removeChild(p2.children[p2.children.length-2]);
			}
		</script>
	</head>
	<body>
		<div id="p2"></div>
		<p align="right">
			<button type="button" onclick="AddPic()">点击加图</button>
			<button type="button" onclick="AddPic2()">点击加图放前面</button>
			<button type="button" onclick="kelong()">克隆</button>
			<button type="button" onclick="delNode()">删除p2的最后一个</button>
		</p>
	</body>
</html>